package com.atguigu.exam;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author xbd
 * @create 2021-05-28 11:17
 */
public class ArrayTest {
    public static void main(String[] args) {
        ArrayList a1 = new ArrayList();
        for (int i = 0; i < 10; i++) {
            a1.add(i);
        }
        System.out.println(a1);
        a1.add(2,"insert");
        System.out.println(a1);
        System.out.println(a1.get(5));
        a1.remove(6);
        System.out.println(a1);
        a1.set(7,"new");
        System.out.println(a1);


        //使用iterator 进行遍历
        Iterator iterator = a1.iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
        System.out.println("***************");
        //使用foreach 进行遍历
        for(Object obj:a1){
            System.out.print(obj + " ");
        }
        System.out.println();
        System.out.println("***************");
        //使用for进行遍历
        for(int i = 0; i < a1.size();i++){
            System.out.print(a1.get(i) + " ");
        }
        System.out.println();
        System.out.println("***************");
        //使用Lambda表达式的forEach  之前没用过这种结构
        a1.forEach(item -> System.out.print(item + " "));



    }
}
